package com.songlanyun.modules.withdrawconfig.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.songlanyun.common.annotation.SysLog;
import com.songlanyun.common.utils.BeanUtil;
import com.songlanyun.common.validator.ValidatorUtils;
import com.songlanyun.modules.systeminfo.entity.SystemInfo;
import com.songlanyun.modules.user.controller.AbstractController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.songlanyun.modules.withdrawconfig.entity.WithdrawConfig;
import com.songlanyun.modules.withdrawconfig.service.WithdrawConfigService;
import com.songlanyun.common.utils.PageUtils;
import com.songlanyun.common.utils.R;


/**
 * 提现设置
 *
 * @author wuchao
 * @email sunlightcs@gmail.com
 * @date 2020-12-18 13:55:07
 */
@RestController
@RequestMapping("admin/withdraw/config")
public class WithdrawConfigController extends AbstractController {
    @Autowired
    private WithdrawConfigService withdrawConfigService;


    /**
     * 信息
     */
    @GetMapping("/info")
    //@RequiresPermissions("withdrawconfig:withdrawConfig:info")
    public R info() {
        List<WithdrawConfig> list = withdrawConfigService.list();
        if (list == null || list.size() == 0) {
            return R.ok().put("data", null);
        }
        return R.ok().put("data", list.get(0));
    }

    /**
     * 保存
     */
    @SysLog("保存修改提现设置")
    @PostMapping("/save")
    //@RequiresPermissions("withdrawconfig:withdrawConfig:save")
    public R save(@RequestBody WithdrawConfig withdrawConfig) {
        verifyAdmin();
        ValidatorUtils.validateEntity(withdrawConfig);
        List<WithdrawConfig> list = withdrawConfigService.list();
        if (list == null || list.size() == 0) {
            //保存
            withdrawConfigService.save(withdrawConfig);
        } else {
            //修改
            withdrawConfig.setId(list.get(0).getId());
            withdrawConfigService.updateById(withdrawConfig);
        }

        return R.ok();
    }

}
